package QRCG;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class ChangePersInfoServe
 */
@WebServlet("/ChangePersInfoServe")
public class ChangePersInfoServe extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ChangePersInfoServe() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession(true);


		String nickname= (String) session.getAttribute("nickname");
		String name= request.getParameter("name");
		String surname= request.getParameter("surname");
		String email= request.getParameter("email");
		String gender= request.getParameter("gender");

		String location= request.getParameter("Loc");
		System.out.println(location);
		String birthday= request.getParameter("birthday");
		String pass1= request.getParameter("pass1");
		String pass2= request.getParameter("pass2");

		int gender_id;

		if(gender.compareTo("male")==0)
		{
			gender_id= 1;
		}
		else
		{
			gender_id=0;
		}

		String query_loc = "SELECT location_id FROM Locations WHERE location_name='"+location+"'";

		deneme dk = new deneme();


		try {
			dk.connect();
			String loc_id = dk.selectOneThing(query_loc);
			String query = "UPDATE Users SET name='"+name+"',surname= '"+surname+"',email= '"+email+"',location_id="+loc_id+",is_male="+gender_id
							+",birth_date= '"+birthday+"',password= '"+pass1+"'"+ "WHERE nickname='"+nickname+"'";

			if(dk.execute(query))
			{
				session.setAttribute("nickname", nickname);
				response.sendRedirect("UserMainPage.jsp");				
			}



		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
